//
//  CRMMarketViewController.m
//  XinKaiFa55like
//
//  Created by 55like on 2017/9/26.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "CRMMarketViewController.h"
#import "RHTableView.h"
#import "BuyerOwnTableViewCell.h"
#import "YYModel.h"
#import "MarkerPlaceViewController.h"

@interface CRMMarketViewController ()

@property(nonatomic,strong)RHTableView * zhltableView;

@end

@implementation CRMMarketViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self.zhltableView reloadData];
    [self makeData];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(makeData) name: @"CRMList" object:nil];
    
}
-(void)makeData{
    
    krequestParam
    [dictparam setObject:@"%@" forKey:@"page"];
    [dictparam setObject:@"20" forKey:@"pagesize"];
    self.zhltableView.urlString=[NSString stringWithFormat:@"customer/slip%@",dictparam.wgetParamStr];
    [self.zhltableView showRefresh:YES LoadMore:YES];
    [self.zhltableView refresh];
    
    
}


static NSString * BuyerOwnTableViewCellID  = @"BuyerOwnTableViewCellID";

-(RHTableView *)zhltableView{
    
    if (!_zhltableView) {
        
        RHTableView * zhltableView =[[RHTableView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight - 64) style:UITableViewStyleGrouped];
        zhltableView.delegate = self;
        zhltableView.dataSource = self;
        zhltableView.backgroundColor = [UIColor whiteColor];
        zhltableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        zhltableView.sectionHeaderHeight = 0;
        
        zhltableView.showsVerticalScrollIndicator = NO;
        zhltableView.showsHorizontalScrollIndicator = NO;
        [self.view addSubview:zhltableView];
        [zhltableView registerClass:[BuyerOwnTableViewCell class] forCellReuseIdentifier:BuyerOwnTableViewCellID];
        _zhltableView = zhltableView;
    }

    return _zhltableView;
}

#pragma mark -  tableview代理方法
- (NSInteger)numberOfSectionsInTableView:(RHTableView *)tableView{
    
    
    return 1;
    
}

-(NSInteger)tableView:(RHTableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    
    return tableView.dataArray.count;
}


-(CGFloat)tableView:(RHTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSDictionary * data = tableView.dataArray[indexPath.row];
    BuyerOwnListModel * model = [BuyerOwnListModel yy_modelWithDictionary:data];

    
    return
    10
    +[[NSString stringWithFormat:@"%@",model.name] HEIGHTwF:15 W:kScreenWidth - 20 - 10]
    +10
    +[[NSString stringWithFormat:@"%@ | %@ | %@",model.mobile,model.wechat,[data valueForJSONStrKey:@"contract"]] HEIGHTwF:13 W:kScreenWidth - 20 - 10]
    +10
    +12
    +10;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    return CGFLOAT_MIN;
}


#pragma mark  cell处理
- (UITableViewCell *)tableView:(RHTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BuyerOwnTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:BuyerOwnTableViewCellID forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.data = tableView.dataArray[indexPath.row];
    
    
    
    
    
    
    
    return cell;
    
}
#pragma mark  选中cell
-(void)tableView:(RHTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSLog(@"%@",indexPath);
    
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setValue:[tableView.dataArray[indexPath.row] valueForJSONStrKey:@"id"] forKey:@"id"];
    

    [self pushController:[MarkerPlaceViewController class] withInfo:dic withTitle:@"销售单入录" withOther:nil];
}










@end
